package pluto.test.base;

import org.junit.After;
import org.junit.BeforeClass;

import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.wall.WallFilter;
import com.jfinal.core.Const;
import com.jfinal.kit.Prop;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.unicom.auth.model._MappingKit;

public class ModelTestCase {

	protected static DruidPlugin dp;
	protected static ActiveRecordPlugin activeRecord;
	private static Prop prop = new Prop("a_little_config.txt",
			Const.DEFAULT_ENCODING);

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		dp = new DruidPlugin(prop.get("jdbcUrl"), prop.get("user"),
				prop.get("password"));

		dp.addFilter(new StatFilter());

		dp.setInitialSize(3);
		dp.setMinIdle(2);
		dp.setMaxActive(5);
		dp.setMaxWait(60000);
		dp.setTimeBetweenEvictionRunsMillis(120000);
		dp.setMinEvictableIdleTimeMillis(120000);

		WallFilter wall = new WallFilter();
		dp.addFilter(wall);

		dp.getDataSource();
		dp.start();

		activeRecord = new ActiveRecordPlugin(dp);
		activeRecord.setDialect(new MysqlDialect()).setDevMode(true)
				.setShowSql(true);

		_MappingKit.mapping(activeRecord);

		activeRecord.start();
	}

	
	@After
	public void tearDown() throws Exception {
		activeRecord.stop();
		dp.stop();
	}

}
